package com.epoint.mobileoa.personalized.epointcompany.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.personalized.epointcompany.bizlogic.GetChuchaijihuadetailListTask;
import com.epoint.mobileoa.personalized.epointcompany.model.ChuchaiDetailListModel;
import com.epoint.mobileoa.service.MainService;

/**
 * @author liyc
 * @time 2012-5-3 下午4:50:57
 * @annotation 
 */
public class ChuchaijihuaDetailListView extends SuperView {
	
	private String dateStr;
	private int taskid;
	private ListView lvCcdt;
	@Override
	public void initControls() {
		lvCcdt = (ListView) findViewById(R.id.lvCcdt);
		dateStr = getIntent().getStringExtra("date");
		top_title.setText(dateStr);
		showDialog_wait(null);
		taskid = 1;
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("dateStr", dateStr);
		Task task = new GetChuchaijihuadetailListTask(this, param);
		MainService.addTask(task);
	}

	private List<ChuchaiDetailListModel> clist = new ArrayList<ChuchaiDetailListModel>();
	
	@Override
	public void refresh(Object... param) {
		if(param[0].toString().equals(MainService.NORMAL)){
			if(taskid==1){
				String bs = param[1].toString();
				clist = GetChuchaijihuadetailListTask.XmlAnalysis(bs);
				MyAdapter adapter = new MyAdapter();
				lvCcdt.setAdapter(adapter);
			}
		}
		m_Dialog.dismiss();
	}

	@Override
	public int getLayoutInt() {
		return R.layout.chuchaijihuadetaillistview;
	}
	
	/*@Override
	public String setTitle() {
		return "出差计划列表";
	}
	*/
	class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			return clist.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				LayoutInflater mInflater = LayoutInflater.from(ChuchaijihuaDetailListView.this);

				convertView = mInflater.inflate(R.layout.chuchaidetaillistview, null);

				holder.tv1 = (TextView) convertView.findViewById(R.id.tv1);
				holder.tv2 = (TextView) convertView.findViewById(R.id.tv2);
				holder.tv3 = (TextView) convertView.findViewById(R.id.tv3);
				holder.tv4 = (TextView) convertView.findViewById(R.id.tv4);
				holder.tv5 = (TextView) convertView.findViewById(R.id.tv5);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			if(position>0){
				if(!clist.get(position-1).OUName.equals(clist.get(position).OUName)){
					holder.tv1.setBackgroundColor(getResources().getColor(R.color.black));
					holder.tv1.setVisibility(View.VISIBLE);
					holder.tv1.setText(Html.fromHtml("<font color=#FFD306>部门:</font><font color='"+getBlackOrWhiteColor()+"'>"+clist.get(position).OUName+"</font>"));
				}
				else{
					holder.tv1.setVisibility(View.GONE);
				}
			}
			else{
				holder.tv1.setVisibility(View.VISIBLE);
				holder.tv1.setBackgroundColor(getResources().getColor(R.color.black));
				holder.tv1.setText(Html.fromHtml("<font color=#FFD306>部门:</font><font color='"+getBlackOrWhiteColor()+"'>"+clist.get(position).OUName+"</font>"));
			}
			
			
			
			holder.tv2.setText(Html.fromHtml("<font color=#FFD306>出差人:</font><font color='"+getBlackOrWhiteColor()+"'>"+clist.get(position).PartnerName+"</font>"));
			holder.tv3.setText(Html.fromHtml("<font color=#FFD306>出差地区:</font><font color='"+getBlackOrWhiteColor()+"'>"+clist.get(position).AreaNames+"</font>"));

			holder.tv4.setText(Html.fromHtml("<font color=#FFD306>出差时间:</font><font color='"+getBlackOrWhiteColor()+"'>"+clist.get(position).ChuChaiTime+"</font>"));
			if(!clist.get(position).WorkContent.equals("")){
				holder.tv5.setVisibility(View.VISIBLE);
				holder.tv5.setText(Html.fromHtml("<font color=#FFD306>备注:</font><font color='"+getBlackOrWhiteColor()+"'>"+clist.get(position).WorkContent+"</font>"));
			}
			else{
				holder.tv5.setVisibility(View.GONE);
			}
			return convertView;
		}
	}

	public class ViewHolder {
		public TextView tv1;
		public TextView tv2;
		public TextView tv3;
		public TextView tv4;
		public TextView tv5;
	}

	@Override
	public void refreshForNewTask(int TaskId,Object... param){
	}

}
